2020-2021 Sunseeker Telemetry and Lighting System
comp_e_ex4_outputToggleVcompVsHalfVcc.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR59xx Demo - COMPE Toggle from LPM4; CompE in LPM4
34 // Vcompare is compared against the Vcc*1/2
35 //
36 // Description: Use CompE and shared reference to determine if input 'Vcompare'
37 // is high of low. When Vcompare exceeds Vcc*1/2 COUT goes high and when
38 // Vcompare is less than Vcc*1/2 then CEOUT goes low.
39 // P3.5/CEOUT is connected internally to an LED; it will toggle accordingly.
40 //
41 // MSP430FR5969
42 // ------------------
43 // /|\| |
44 // | | |
45 // --|RST P1.2/CE2 |<--Vcompare
46 // | |
47 // | P3.5/CEOUT|----> 'high'(Vcompare>Vcc*1/2); 'low'(Vcompare<Vcc*1/2)
48 // | | |
49 // | | | LED 'ON'(Vcompare>Vcc*1/2); 'OFF'(Vcompare<Vcc*1/2)
50 // | |
51 //
52 //******************************************************************************
53 #include "driverlib.h"
54 
55 void main(void)
56 {
57  //Stop WDT
58  WDT_A_hold(WDT_A_BASE);
59 
60  //Set P3.5 as Ternary Module Function Output.
61  /*
62 
63  * Select Port 3
64  * Set Pin 5 to output Ternary Module Function, (CEOUT).
65  */
66  GPIO_setAsPeripheralModuleFunctionOutputPin(
67  GPIO_PORT_P3,
68  GPIO_PIN5,
69  GPIO_TERNARY_MODULE_FUNCTION
70  );
71 
72  /*
73  * Disable the GPIO power-on default high-impedance mode to activate
74  * previously configured port settings
75  */
76  PMM_unlockLPM5();
77 
78  //Initialize the Comparator E module
79  /* Base Address of Comparator E,
80  * Pin C2 to Positive(+) Terminal,
81  * Reference Voltage to Negative(-) Terminal,
82  * Normal Power Mode,
83  * Output Filter On with minimal delay,
84  * Non-Inverted Output Polarity
85  */
86  Comp_E_initParam param = {0};
87  param.posTerminalInput = COMP_E_INPUT2;
88  param.negTerminalInput = COMP_E_VREF;
89  param.outputFilterEnableAndDelayLevel = COMP_E_FILTEROUTPUT_OFF;
90  param.invertedOutputPolarity = COMP_E_NORMALOUTPUTPOLARITY;
91  Comp_E_init(COMP_E_BASE, &param);
92 
93  //Set the reference voltage that is being supplied to the (-) terminal
94  /* Base Address of Comparator E,
95  * Reference Voltage of Vcc V,
96  * Lower Limit of Vcc*(16/32) = Vcc*1/2,
97  * Upper Limit of Vcc*(16/32) = Vcc*1/2
98  */
99  Comp_E_setReferenceVoltage(COMP_E_BASE,
100  COMP_E_REFERENCE_AMPLIFIER_DISABLED,
101  16,
102  16
103  );
104 
105  //Disable Input Buffer on P1.2/CE2
106  /* Base Address of Comparator E,
107  * Input Buffer port
108  * Selecting the CEx input pin to the comparator
109  * multiplexer with the CEx bits automatically
110  * disables output driver and input buffer for
111  * that pin, regardless of the state of the
112  * associated CEPE.x bit
113  */
114  Comp_E_disableInputBuffer(COMP_E_BASE,
115  COMP_E_INPUT2);
116 
117  //Allow power to Comparator module
118  Comp_E_enable(COMP_E_BASE);
119 
120  __delay_cycles(400); // delay for the reference to settle
121 
122  __bis_SR_register(LPM4_bits); // Enter LPM4
123  __no_operation(); // For debug
124 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)